import React from 'react'
import { ErrorBlock, Button } from 'antd-mobile'
import { connect, useHistory } from 'umi'
import './checking.less'

function Checking(props: any) {
    const phone='15919848709'
    let userInfo=sessionStorage.getItem('userInfo')
    userInfo=userInfo?JSON.parse(userInfo):{}
    const history=useHistory()
    const callAdmin=()=>{
        // console.log('callAdmin')
        window.location.href= `tel:${phone}`
    }
    console.log(userInfo,props.checking)
    const reloadStatus=()=>{
        fetch("/admin/base/comm/person",{
            method:"POST",
            body:JSON.stringify(userInfo),
            headers:{
                "Content-Type":"application/json"
            }
        }).then(res=>res.json()).then(res=>{
            console.log(res)
            if(res.code!='1000') return
            sessionStorage.setItem('userInfo',JSON.stringify(res.data))
            props.dispatch({
                type:'example/setUserInfo',
                payload:res.data
            })
        })
    }
    return (
        <div className='checking'>
            {
                props.checking == '2' && (
                    <ErrorBlock description='请稍后再试' title='审核不通过' status='default' />
                )
            }
            {
                props.checking == '0' && (
                    <ErrorBlock description='请稍后再试' title='账号审核中' status='busy' />
                )
            }
            {
                props.checking == '2' ? (
                    <>
                    <Button color='warning' onClick={callAdmin}>请联系{phone}</Button>
                    <br></br>
                    <Button color='success' onClick={()=>history.push('/login')}>重新登录</Button>
                    
                    </>
                ):<Button color='warning' onClick={reloadStatus}>刷新</Button>
            }
        </div>
    )
}
export default connect((state: any) => {
    return {
        checking: state.example.checking
    }
})(Checking)